/**
 * 
 */
package myTeam.timeShop.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import myTeam.timeShop.bean.TbRequest;
import myTeam.timeShop.dao.RequestDao;
import myTeam.timeShop.entity.Request;
import myTeam.timeShop.entity.User;
import myTeam.timeShop.service.RequestService;

/**
 * @author jiangjintai
 *
 */
@Service("requestService")
public class RequestServiceImpl implements RequestService {
	@Autowired
	RequestDao requestDao;
	/* （非 Javadoc）
	 * @see myTeam.timeShop.service.GenericService#load(java.lang.Object)
	 */
	@Override
	public TbRequest load(String id) {
		// TODO 自动生成的方法存根
		return this.requestDao.load(id);
	}

	/* （非 Javadoc）
	 * @see myTeam.timeShop.service.GenericService#get(java.lang.Object)
	 */
	@Override
	public TbRequest get(String id) {
		// TODO 自动生成的方法存根
		return this.requestDao.get(id);
	}

	/* （非 Javadoc）
	 * @see myTeam.timeShop.service.GenericService#findAll()
	 */
	@Override
	public List<TbRequest> findAll() {
		// TODO 自动生成的方法存根
		return this.requestDao.findAll();
	}

	/* （非 Javadoc）
	 * @see myTeam.timeShop.service.GenericService#persist(java.lang.Object)
	 */
	@Override
	public void persist(TbRequest entity) {
		// TODO 自动生成的方法存根
		this.requestDao.persist(entity);
	}

	/* （非 Javadoc）
	 * @see myTeam.timeShop.service.GenericService#save(java.lang.Object)
	 */
	@Override
	public String save(TbRequest entity) {
		// TODO 自动生成的方法存根
		return this.requestDao.save(entity);
	}

	/* （非 Javadoc）
	 * @see myTeam.timeShop.service.GenericService#saveOrUpdate(java.lang.Object)
	 */
	@Override
	public void saveOrUpdate(TbRequest entity) {
		// TODO 自动生成的方法存根
		this.requestDao.saveOrUpdate(entity);
		
	}

	/* （非 Javadoc）
	 * @see myTeam.timeShop.service.GenericService#delete(java.lang.Object)
	 */
	@Override
	public void delete(String id) {
		// TODO 自动生成的方法存根
		this.requestDao.delete(id);
	}

	/* （非 Javadoc）
	 * @see myTeam.timeShop.service.GenericService#flush()
	 */
	@Override
	public void flush() {
		// TODO 自动生成的方法存根
		this.requestDao.flush();
	}

	/* （非 Javadoc）
	 * @see myTeam.timeShop.service.RequestService#updateMyRequest(java.lang.String, java.lang.String)
	 */
	@Override
	
	public void updateMyRequest(String requestId, String type) {
		TbRequest tbRequest = this.get(requestId);
		if(type.equals("1")){//代表允许请求
			tbRequest.setRequestStatus(1);
		}else{//代表取消请求
			tbRequest.setRequestStatus(-1);
		}
		this.saveOrUpdate(tbRequest);
	}

	/* （非 Javadoc）
	 * @see myTeam.timeShop.service.RequestService#getAllMyNoSeeRequest(java.lang.String)
	 */
	@Override
	
	public List<TbRequest> getAllMyNoSeeRequest(String filterUserId) {
		List<TbRequest> tbRequestList = this.requestDao.getAllMyNoSeeRequest(filterUserId);
		List<TbRequest> requestList = new ArrayList<TbRequest>();
		for(TbRequest r:tbRequestList){
			Request request =new Request();
			request.setRequestClientId(r.getTbUser().getUserId());
			request.setRequestDemandId(r.getTbDemand().getDemandId());
			request.setRequestId(r.getRequestId());
			request.setRequestMessage(r.getRequestMessage());
			request.setRequestStatus(r.getRequestStatus());
			request.setRequestTime(r.getRequestTime());
			
			User user = new User();
			user.setUserAccount(r.getTbUser().getUserAccount());
			user.setUserFacePath(r.getTbUser().getUserFacePath());
			user.setUserId(r.getTbUser().getUserId());
			user.setUserLevel(r.getTbUser().getUserLevel());
			user.setUserName(r.getTbUser().getUserName());
			user.setUserSchool(r.getTbUser().getUserSchool());
			user.setUserSex(r.getTbUser().getUserSex());
			request.setTbUser(user);
			requestList.add(request);
		}
		return requestList;
	} 

}
